package com.ywu.application.standard.thirdExec.api;

import com.ywu.common.gson.GsonUtils;
import com.ywu.common.result.CommonResult;
import com.ywu.application.standard.thirdExec.dto.YwuThirdExecVersionDto;
import com.ywu.application.standard.thirdExec.dto.YwuThirdExecVersionParamListDto;
import com.ywu.application.standard.thirdExec.service.YwuThirdExecVersionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName YwuThirdExecVersionApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/10/11 14:49
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/third/exec/version")
public class YwuThirdExecVersionApi {
    @Autowired
    private YwuThirdExecVersionService service;

    /**
    * @Author GroundDemo
    * @Description 查询执行脚本的历史版本
    * @Date 15:05 2024/10/11
    * @Param [thirdExecVersionDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/query.third.exec.version.info")
    public CommonResult<Object> queryThirdExecVersionList(@RequestBody YwuThirdExecVersionDto thirdExecVersionDto) {
        return service.queryThirdExecVersionList(thirdExecVersionDto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除草稿版本的数据
    * @Date 15:07 2024/10/11
    * @Param [thirdExecVersionDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/delete.third.exec.draft.version.info")
    public CommonResult<Object> deleteDraftVersion(@RequestBody YwuThirdExecVersionDto thirdExecVersionDto) {
        return service.deleteDraftVersion(thirdExecVersionDto);
    }

    /**
    * @Author GroundDemo
    * @Description 回退历史版本的数据
    * @Date 15:08 2024/10/11
    * @Param [thirdExecVersionDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/back.third.exec.version.info")
    public CommonResult<Object> backThirdExecVersion(@RequestBody YwuThirdExecVersionDto thirdExecVersionDto) {
        return service.backThirdExecVersion(thirdExecVersionDto);
    }

    /**
    * @Author GroundDemo
    * @Description 脚本内容查看
    * @Date 19:20 2024/10/15
    * @Param [thirdExecVersionDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/third.exec.version.content.info")
    public CommonResult<Object> thirdExecContentView(@RequestBody YwuThirdExecVersionDto thirdExecVersionDto) {
        return service.thirdExecContentView(thirdExecVersionDto);
    }

    /**
    * @Author GroundDemo
    * @Description 执行历史版本的脚本
    * @Date 22:13 2024/10/15
    * @Param [thirdExecVersionDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/do.third.exec.version.source.id")
    public CommonResult<Object> doThirdExecVersion(@RequestBody YwuThirdExecVersionParamListDto ywuThirdExecVersionParamListDto) {
        YwuThirdExecVersionDto thirdExecVersionDto = new YwuThirdExecVersionDto();
        BeanUtils.copyProperties(ywuThirdExecVersionParamListDto, thirdExecVersionDto, "execParam");
        thirdExecVersionDto.setExecParam(GsonUtils.serialize(ywuThirdExecVersionParamListDto.getExecParam()));
        return service.doThirdExecVersion(thirdExecVersionDto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询历史版本详情
    * @Date 22:13 2024/10/15
    * @Param [thirdExecVersionDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/third.exec.version.info")
    public CommonResult<Object> thirdExecVersionInfo(@RequestBody YwuThirdExecVersionDto thirdExecVersionDto) {
        return service.thirdExecVersionInfo(thirdExecVersionDto);
    }
}
